package cn.tpshion.devops.controller;

import cn.tpshion.devops.common.Result;
import cn.tpshion.devops.domain.dto.TaskStatusDTO;
import cn.tpshion.devops.domain.dto.TaskWorkDTO;
import cn.tpshion.devops.service.NodeService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping("/node")
public class NodeController {

    @Resource
    private NodeService nodeService;

    @PostMapping("/start")
    public Result start(@Valid @RequestBody TaskWorkDTO dto){
        nodeService.start(dto);
        return Result.ok();
    }

    @PostMapping("/stop")
    public Result stop(@Valid @RequestBody TaskWorkDTO dto){
        nodeService.stopTask(dto);
        return Result.ok();
    }

    @PostMapping("/taskStatus")
    public Result<TaskStatusDTO> taskStatus(@Valid @RequestBody TaskWorkDTO dto){
        return Result.ok(nodeService.taskStatus(dto));
    }

    @PostMapping("/runStatus")
    public Result<Boolean> runStatus(@Valid @RequestBody TaskWorkDTO dto){
        return Result.ok(nodeService.runStatus(dto));
    }
}
